// ----------------------------------
// RSDK Project: Sonic 1 Forever X Doki Doki Literature Club
// Script Description: Menu Control
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 1 : TYPE_SEGA
private alias 75 : SPACING_VALUE

private alias object.value0 : object.currentSelection
private alias object.value1 : object.drawPos.x
private alias object.value2 : object.drawPos.y
private alias object.value3 : object.stringLength
private alias object.value4 : object.letterID
private alias object.value5 : object.index
private alias object.value6 : object.fontSize
private alias object.value7 : object.textCenterIt
private alias object.value8 : object.menuLine
private alias object.value9 : object.curMenu
private alias object.value10 : object.leftPartX
private alias object.value11 : object.rightPartX
private alias object.value12 : frame.count
private alias object.value13 : speen.timer
private alias object.value14 : speen.x
private alias object.value15 : scroll.min
private alias object.value16 : scroll.max
private alias object.value17 : scroll.current
private alias object.value18 : object.deleteSelect 
private alias object.value19 : object.alphaArrows 
private alias object.value20 : object.touchSfxDelay 

private alias 0 : FONT_SMALL
private alias 1 : FONT_LARGE
private alias 2 : FONT_TINY
private alias 8 : BOX_OFFSET

//Static Values
private value saved.fullscreen = 0;
private value saved.scale = 0;
private value saved.vsync = 0;
private value saved.scalemode = 0;
private value saved.fps = 0;
private value enableModOption = 0;
private value optionYSpace = 0;
private value optionMobileDrawerHelper = 0;
private value MenuBackButton = 0;

// Function declarations
reserve function main.sound
reserve function Options_DrawTextString
reserve function DrawOptionLeft
reserve function DrawOptionRight
reserve function DrawDataOption

reserve function display.menu
reserve function gameplay.menu
reserve function abilities.menu
reserve function visuals.menu
reserve function sound.menu
reserve function datamang.menu
reserve function modOptions.menu

reserve function display.draw
reserve function gameplay.draw
reserve function abilities.draw
reserve function visuals.draw
reserve function sound.draw
reserve function datamang.draw
reserve function modOptions.draw

reserve function delete.save
reserve function delete.ta
reserve function delete.arcade
reserve function delete.golf
reserve function delete.extra
reserve function delete.achieve
reserve function delete.secret
reserve function option.restore

private table MenuControl_LetterWidth
	10, 9, 10, 10, 8, 8, 11, 9, 4, 9, 10, 7, 12, 10, 11, 9, 11, 9, 9, 9, 10, 10, 15, 9, 9, 9, 
	9, 9, 9, 8, 9, 9, 8, 8, 8, 5, 7, 8, 6, 11, 8, 8, 8, 8, 7, 7, 7, 9, 7, 11, 8, 9, 7
end table

private table MenuControl_LetterWidthLarge
	19, 15, 18, 18, 15, 14, 19, 16, 7, 14, 16, 13, 21, 19, 20, 16, 20, 15, 15, 17, 17, 19, 27, 18, 18, 16     
end table

private table MenuControl_LetterWidthNumbers
	10, 6, 9, 9, 9, 9, 9, 9, 9, 9
end table

private table MenuControl_RandomCharacters
	6 // Space
	0 // @
	4 // . and !
	1 // tiny randos
	7 // -
	10 // &
end table

private table MenuControl_TinyLetterWidth
	4, 3, 4, 4, 3, 3, 4, 4, 3, 3, 3, 3, 5, 4, 4, 3, 5, 3, 3, 3, 4, 5, 5, 3, 3, 3 // upper
	4, 3, 3, 3, 3, 2, 3, 3, 1, 3, 3, 1, 5, 3, 3, 3, 4, 2, 3, 3, 3, 3, 5, 3, 3, 3 // lower
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3 // numbers
end table

function delete.save
	arrayPos0 = 1000
	while arrayPos0 <= 1103
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.ta
	arrayPos0 = 470
	while arrayPos0 <= 607
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.arcade
	arrayPos0 = 620
	while arrayPos0 <= 640
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.golf
	arrayPos0 = 720
	while arrayPos0 <= 740
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.extras
	arrayPos0 = 650
	while arrayPos0 <= 652
	    saveRAM[arrayPos0] = 59999
	    arrayPos0++
	loop

	arrayPos0 = 994
	while arrayPos0 <= 999
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.achieve
	arrayPos0 = 400
	while arrayPos0 <= 411
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop

	arrayPos0 = 414
	while arrayPos0 <= 416
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop

	arrayPos0 = 418
	while arrayPos0 <= 422
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()
end function

function delete.secret
	saveRAM[412] = 0
	saveRAM[413] = 0
	saveRAM[417] = 0
	saveRAM[280] = 0
	WriteSaveRAM()
end function

function option.restore
	Engine.BGMVolume = 40
	Engine.SFXVolume = 40

	arrayPos0 = 257
	while arrayPos0 <= 285
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop

	saveRAM[287] = 0
	saveRAM[290] = 0
	saveRAM[294] = 0

	arrayPos0 = 296
	while arrayPos0 <= 301
	    saveRAM[arrayPos0] = 0
	    arrayPos0++
	loop
	WriteSaveRAM()

	LoadPalette("MainMenu.act", 1, 0, 0, 256)
	LoadPalette("ddlcstage.act", 0, 96, 0, 256)
	LoadPalette("SpecialStage.act", 0, 0, 0, 96)				
	LoadPalette("ElectricFlash.act", 3, 0, 0, 256)				
	CreateTempObject(TypeName[Palette Police], saved.graphics, 0, 0)
	temp0 = 0
	while temp0 < 256
		GetPaletteEntry(1, temp0, temp1)			
		temp2 = temp1
		temp2 &= 0xE00000
		temp2 >>= 21
		switch saved.graphics
		case 0
			switch temp2
				case 0
					temp2 = 0
					break
				case 1
					temp2 = 8
					break
				case 2
					temp2 = 16
					break
				case 3
					temp2 = 32
					break
				case 4
					temp2 = 64
					break
				case 5
					temp2 = 96
					break
				case 6
					temp2 = 128
					break
				case 7
					temp2 = 160
					break
			end switch
			break
		case 1	
			switch temp2
				case 0
					temp2 = 0
					break
				case 1
					temp2 = 9
					break
				case 2
					temp2 = 18
					break
				case 3
					temp2 = 36
					break
				case 4
					temp2 = 72
					break
				case 5
					temp2 = 108
					break
				case 6
					temp2 = 144
					break
				case 7
					temp2 = 180
					break
			end switch	
			break
		case 2	
			switch temp2
				case 0
					temp2 = 0
					break
				case 1	
					temp2 = 13
					break	
				case 2
					temp2 = 26
					break	
				case 3
					temp2 = 52
					break
				case 4
					temp2 = 87
					break
				case 5
					temp2 = 116
					break
				case 6
					temp2 = 144
					break
				case 7
					temp2 = 172
					break
			end switch
			break
		end switch	
		temp3 = temp2
		temp3 <<= 16				
		
		temp4 = temp2
		temp4 <<= 8
		
		temp5 = temp2	

		temp1 = temp3
		temp1 += temp4
		temp1 += temp5
		SetPaletteEntry(2, temp0, temp1)
		temp0++
	loop		
end function

function main.sound	
	temp0 = inputPress.left
	temp0 |= inputPress.right
	temp0 |= inputPress.up
	temp0 |= inputPress.down
	temp0 |= inputPress.buttonL
	temp0 |= inputPress.buttonR
	if temp0 == 1
		PlaySfx(SfxName[Hover], 0)
	end if
end function

function DrawOptionLeft
	if optionMobileDrawerHelper == 0
		if object.state == 0
			ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Options], 1, 0, 0)
			temp0 = -12
			temp0 *= object.menuLine
			object[arrayPos0].alpha = temp0
			object[arrayPos0].value40 = 256
			object[arrayPos0].state = 0
		end if		
		object[arrayPos0].index = object.index
		object[arrayPos0].fontSize = FONT_SMALL
		object[arrayPos0].drawPos.y = object.drawPos.y
		object[arrayPos0].menuLine = object.menuLine
		object[arrayPos0].priority = PRIORITY_ACTIVE
		object[arrayPos0].drawOrder = OPTIONS_DRAWORDER
		if saved.mobile == 1
			object[arrayPos0].drawPos.x = object.drawPos.x
			object[arrayPos0].textCenterIt = 1	
			temp0 = object.drawPos.x
			temp0 -= 90
			temp1 = temp0
			temp1 += 180
			temp2 = object.drawPos.y
			temp2 -= scroll[OPTIONS_SLOT].current
			temp3 = temp2
			temp3 += 16

			if optionCheck == 0
				if temp2 > 52
					CheckTouchRect(temp0, temp2, temp1, temp3)
					if checkResult > -1
						if object[arrayPos0].touchSfxDelay == false
							if object.currentSelection == object.menuLine
								optionCheck = 1
								PlaySfx(SfxName[Select], false)
							else
								object.currentSelection = object.menuLine
								PlaySfx(SfxName[Hover], false)
							end if	


							object[arrayPos0].touchSfxDelay = true
						end if
					else
						object[arrayPos0].touchSfxDelay = false		
					end if	
				end if	
			end if	
		
		else
			object[arrayPos0].drawPos.x = object.leftPartX
			object[arrayPos0].textCenterIt = 0
		end if
	end if	
end function


function DrawDataOption
	if object.state == 0
		ResetObjectEntity(object[arrayPos1].entityPos, TypeName[Options], 1, 0, 0)
		temp0 = -12
		temp0 *= object.menuLine
		object[arrayPos1].alpha = temp0
		object[arrayPos1].value40 = 256
		object[arrayPos1].state = 0
	end if		
	object[arrayPos1].index = object.index
	object[arrayPos1].fontSize = FONT_SMALL
	object[arrayPos1].textCenterIt = 1
	object[arrayPos1].drawPos.x = object.drawPos.x
	object[arrayPos1].drawPos.y = object.drawPos.y
	object[arrayPos1].menuLine = object.menuLine	
	object[arrayPos1].priority = PRIORITY_ACTIVE	
	object[arrayPos1].drawOrder = OPTIONS_DRAWORDER

	if saved.mobile == 1
		if deleteCheck == 0
			object[arrayPos0].drawPos.x = object.drawPos.x
			object[arrayPos0].textCenterIt = 1	
			temp0 = object.drawPos.x
			temp0 -= 90
			temp1 = temp0
			temp1 += 180
			temp2 = object.drawPos.y
			temp2 -= scroll[OPTIONS_SLOT].current
			temp3 = temp2
			temp3 += 16

			if temp2 > 52
				CheckTouchRect(temp0, temp2, temp1, temp3)
				if checkResult > -1
					if object[arrayPos0].touchSfxDelay == false
						if object.currentSelection == object.menuLine
							PlaySfx(SfxName[Select], false)
							deleteCheck = 1
							object.deleteSelect = 1
						else
							object.currentSelection = object.menuLine
						end if	

						PlaySfx(SfxName[Hover], false)
						object[arrayPos0].touchSfxDelay = true
					end if
				else
					object[arrayPos0].touchSfxDelay = false		
				end if	
			end if	
		end if	
	end if	

	object.drawPos.y += optionYSpace
	object.menuLine++
	arrayPos0++
	arrayPos1++
end function


function DrawOptionRight
	if object.state == 0
		ResetObjectEntity(object[arrayPos1].entityPos, TypeName[Options], 1, 0, 0)
		temp0 = -12
		temp0 *= object.menuLine
		object[arrayPos1].alpha = temp0
		object[arrayPos1].value40 = 256
		object[arrayPos1].state = 0
	end if	
	object[arrayPos1].index = object.index
	object[arrayPos1].fontSize = FONT_SMALL

	object[arrayPos1].menuLine = object.menuLine	
	object[arrayPos1].priority = PRIORITY_ACTIVE	
	if saved.mobile == 1
		object[arrayPos1].propertyValue = 2
		object[arrayPos1].drawPos.x = screen.xcenter
		object[arrayPos1].drawPos.y = screen.ycenter
		object[arrayPos1].drawPos.y += 10
		object[arrayPos1].textCenterIt = 1		
		if object.currentSelection == object.menuLine
			if optionCheck == 1
				object[arrayPos1].drawOrder = 6
			else
				object[arrayPos1].drawOrder = 0
			end if	
		else		
			object[arrayPos1].drawOrder = 0
		end if	
	else
		object[arrayPos1].textCenterIt = 2
		object[arrayPos1].drawPos.x = object.rightPartX
		object[arrayPos1].drawPos.y = object.drawPos.y
		object[arrayPos1].drawOrder = OPTIONS_DRAWORDER
	end if	
	object.drawPos.y += optionYSpace
	object.menuLine++
	arrayPos0++
	arrayPos1++		
end function

function Options_DrawTextString
	temp0 = object.drawPos.x

	temp7 = 0
	if object.textCenterIt >= 1
		arrayPos0 = 0
		GetTextInfo(temp1, 2, TEXTINFO_TEXTSIZE, object.index, 0)

		// Now cycle through the letters in the string
		while temp1 > 0
			GetTextInfo(object.letterID, 2, TEXTINFO_TEXTDATA, object.index, arrayPos0)
			object.frame = object.letterID

			switch object.fontSize
			case FONT_SMALL
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame -= 64
						temp3 = MenuControl_LetterWidth
						temp5 = object.frame
						temp5--
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame -= 69
						temp3 = MenuControl_LetterWidth
						temp5 = object.frame
						temp5--
					end if
				end if

				if object.letterID >= 48
					if object.letterID <= 57
						object.frame += 163
						temp3 = MenuControl_LetterWidthNumbers
						temp5 = object.letterID
						temp5 -= 48
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_RandomCharacters
					temp5 = 0
				end if
				if object.letterID == 46
					object.frame = 158
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if
				if object.letterID == 33
					object.frame = 159
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if
				if object.letterID == 58
					object.frame = 209
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if
				if object.letterID == 45
					object.frame = 210
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if
				if object.letterID == 39
					object.frame = 221
					temp3 = MenuControl_RandomCharacters
					temp5 = 2
				end if
				if object.letterID == 34
					object.frame = 222
					temp3 = MenuControl_RandomCharacters
					temp5 = 4
				end if
				if object.letterID == 38
					object.frame = 223
					temp3 = MenuControl_RandomCharacters
					temp5 = 5				
				end if				
				if object.letterID == 64
					object.drawPos.y += 15
					object.frame = 0
					temp0 = object.drawPos.x
					temp3 = MenuControl_RandomCharacters
					temp5 = 1				
				end if
				break
			case FONT_LARGE	
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame -= 11
						temp3 = MenuControl_LetterWidthLarge
						temp5 = object.letterID
						temp5 -= 65
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame -= 17
						temp3 = MenuControl_LetterWidthLarge
						temp5 = object.letterID
						temp5 -= 97
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_RandomCharacters
					temp5 = 0
				end if
				break

			case FONT_TINY
				if object.letterID >= 65
					if object.letterID <= 90
						object.frame += 41
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.letterID
						temp5 -= 65
					end if
				end if

				if object.letterID >= 97
					if object.letterID <= 122
						object.frame += 35
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.letterID
						temp5 -= 97
						temp5 += 26
					end if
				end if

				if object.letterID >= 48
					if object.letterID <= 57
						object.frame += 123
						temp3 = MenuControl_TinyLetterWidth
						temp5 = object.letterID
						temp5 -= 48
						temp5 += 26
						temp5 += 26
					end if
				end if

				if object.letterID == 32
					object.frame = 0
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1
				end if

				if object.letterID == 64
					object.drawPos.y += 8
					object.frame = 0
					temp0 = object.drawPos.x
					temp3 = MenuControl_RandomCharacters
					temp5 = 1				
				end if
				if object.letterID == 46
					object.frame = 205
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				if object.letterID == 63
					object.frame = 225
					temp3 = MenuControl_TinyLetterWidth
					temp5 = 1			
				end if			
				if object.letterID == 44
					object.frame = 206
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				if object.letterID == 33
					object.frame = 208
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if					
				if object.letterID == 39
					object.frame = 207
					temp3 = MenuControl_RandomCharacters
					temp5 = 3				
				end if			
				break
			end switch


			// Move on to the next letter that we've stored
			arrayPos0++

			// Then decrease the amount of letters we have left
			temp1--

			// Finally, space out each character
			GetTableValue(temp4, temp5, temp3)
			temp7 += temp4
			if object.fontSize == FONT_TINY
				temp7++
			else
				temp7--
			end if	
		loop
	end if
	if object.textCenterIt == 1
		temp7 /= 2
	end if	
	temp0 -= temp7

	arrayPos0 = 0

	GetTextInfo(temp1, 2, TEXTINFO_TEXTSIZE, object.index, 0)

	// Now cycle through the letters in the string
	while temp1 > 0
		GetTextInfo(object.letterID, 2, TEXTINFO_TEXTDATA, object.index, arrayPos0)
		object.frame = object.letterID
		if object.menuLine != -10
			if object[OPTIONS_SLOT].currentSelection == object.menuLine
				CopyPalette(0, 149, 0, 50, 1)
			end if
		end if	

		if object.menuLine == -11
			if object.deleteSelect == 0
				CopyPalette(0, 149, 0, 50, 1)
			end if
		end if
		if object.menuLine == -12
			if object.deleteSelect == 1
				CopyPalette(0, 149, 0, 50, 1)
			end if
		end if

		switch object.fontSize
		case FONT_SMALL
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame -= 64
					temp3 = MenuControl_LetterWidth
					temp5 = object.frame
					temp5--
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame -= 69
					temp3 = MenuControl_LetterWidth
					temp5 = object.frame
					temp5--
				end if
			end if

			if object.letterID >= 48
				if object.letterID <= 57
					object.frame += 163
					temp3 = MenuControl_LetterWidthNumbers
					temp5 = object.letterID
					temp5 -= 48
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_RandomCharacters
				temp5 = 0
			end if
			if object.letterID == 46
				object.frame = 158
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 33
				object.frame = 159
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 58
				object.frame = 209
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 45
				object.frame = 210
				temp3 = MenuControl_RandomCharacters
				temp5 = 4
			end if
			if object.letterID == 39
				object.frame = 221
				temp3 = MenuControl_RandomCharacters
				temp5 = 2
			end if
			if object.letterID == 34
				object.frame = 222
				temp3 = MenuControl_RandomCharacters
				temp5 = 4
			end if
			if object.letterID == 38
				object.frame = 223
				temp3 = MenuControl_RandomCharacters
				temp5 = 5				
			end if				
			if object.letterID == 64
				object.drawPos.y += 15
				object.frame = 0
				temp0 = object.drawPos.x
				temp3 = MenuControl_RandomCharacters
				temp5 = 1				
			end if
			break
		case FONT_LARGE	
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame -= 11
					temp3 = MenuControl_LetterWidthLarge
					temp5 = object.letterID
					temp5 -= 65
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame -= 17
					temp3 = MenuControl_LetterWidthLarge
					temp5 = object.letterID
					temp5 -= 97
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_RandomCharacters
				temp5 = 0
			end if
			break

		case FONT_TINY
			if object.letterID >= 65
				if object.letterID <= 90
					object.frame += 41
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 65
				end if
			end if

			if object.letterID >= 97
				if object.letterID <= 122
					object.frame += 35
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 97
					temp5 += 26
				end if
			end if

			if object.letterID >= 48
				if object.letterID <= 57
					object.frame += 123
					temp3 = MenuControl_TinyLetterWidth
					temp5 = object.letterID
					temp5 -= 48
					temp5 += 26
					temp5 += 26
				end if
			end if

			if object.letterID == 32
				object.frame = 0
				temp3 = MenuControl_TinyLetterWidth
				temp5 = 1
			end if

			if object.letterID == 64
				object.drawPos.y += 8
				object.frame = 0
				temp0 = object.drawPos.x
				temp3 = MenuControl_RandomCharacters
				temp5 = 1				
			end if
			if object.letterID == 46
				object.frame = 205
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.letterID == 63
				object.frame = 225
				temp3 = MenuControl_TinyLetterWidth
				temp5 = 1			
			end if			
			if object.letterID == 44
				object.frame = 206
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.letterID == 33
				object.frame = 208
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if					
			if object.letterID == 39
				object.frame = 207
				temp3 = MenuControl_RandomCharacters
				temp5 = 3				
			end if			
			if object.menuLine != -10
				CopyPalette(0, 154, 0, 1, 1)
			end if	
			break
		end switch

		// Now we'll start drawing
		DrawSpriteScreenFX(object.frame, FX_INK, temp0, object.drawPos.y)

		// Move on to the next letter that we've stored
		arrayPos0++

		// Then decrease the amount of letters we have left
		temp1--

		// Finally, space out each character
		GetTableValue(temp4, temp5, temp3)
		temp0 += temp4
		if object.fontSize == FONT_TINY
			temp0++
		else
			temp0--
		end if	

		CopyPalette(0, 171, 0, 50, 1)	
		SetPaletteEntry(0, 1, 0)
	loop

	// set it back so nothing bad happens
	object.textCenterIt = 0
end function

function display.menu
	CallFunction(main.sound)
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			if saved.mobile == 1
				object.currentSelection = 9
			else
				object.currentSelection = 8
			end if
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if saved.mobile == 1
				if object.currentSelection > 9
					object.currentSelection = 0
				end if
			else
				if object.currentSelection > 8
					object.currentSelection = 0
				end if
			end if
		end if
	end if
	
	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		if enableModOption == 1
			object.curMenu = 6
		else
			object.curMenu = 5
		end if	
		object.currentSelection = 0
		object.state = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu++
			object.state = 0
			object.currentSelection = 0
		end if		
	end if

	switch object.currentSelection
		case 0 //Display Highlighted
			break
		case 1 // Fullscreen
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.fullscreen ^= 1
				CallNativeFunction2(SetWindowFullScreen, saved.fullscreen, 0)
			end if
			break
		case 2 // Screen Width		
			if inputPress.left == 1
				switch screen.xsize
					case 320
						CallNativeFunction2(SetScreenWidth, 384, 0)
						break
					case 384
						CallNativeFunction2(SetScreenWidth, 426, 0)
						break
					case 426
						CallNativeFunction2(SetScreenWidth, 320, 0)
						break
					default
						CallNativeFunction2(SetScreenWidth, 426, 0)
						break
				end switch
			end if
			if inputPress.right == 1
				switch screen.xsize
					case 320
						CallNativeFunction2(SetScreenWidth, 426, 0)
						break
					case 384
						CallNativeFunction2(SetScreenWidth, 320, 0)
						break
					case 426
						CallNativeFunction2(SetScreenWidth, 384, 0)
						break
					default
						CallNativeFunction2(SetScreenWidth, 426, 0)
						break
				end switch
			end if
			break
		case 3 // Window Scale		
			if inputPress.left == 1					
				saved.scale--
				if saved.scale < 1
					saved.scale = 4
				end if
				CallNativeFunction2(SetWindowScale, saved.scale, 0)
			end if
			if inputPress.right == 1
				saved.scale++
				if saved.scale > 4
					saved.scale = 1
				end if
				CallNativeFunction2(SetWindowScale, saved.scale, 0)
			end if
			break
		case 4 // Graphics Mode
			temp0 = 0
			if inputPress.left == 1
				temp0 = 1
				saved.graphics--
				if saved.graphics < 0
					saved.graphics = 2
				end if
			end if
			if inputPress.right == 1
				temp0 = 1
				saved.graphics++
				if saved.graphics > 2
					saved.graphics = 0
				end if
			end if
			if temp0 == 1
				LoadPalette("MainMenu.act", 1, 0, 0, 256)
				LoadPalette("ddlcstage.act", 0, 96, 0, 256)
				LoadPalette("SpecialStage.act", 0, 0, 0, 96)				
				LoadPalette("ElectricFlash.act", 3, 0, 0, 256)				
				CreateTempObject(TypeName[Palette Police], saved.graphics, 0, 0)
				temp0 = 0
				while temp0 < 256
					GetPaletteEntry(1, temp0, temp1)			
					temp2 = temp1
					temp2 &= 0xE00000
					temp2 >>= 21
					switch saved.graphics
					case 0
						switch temp2
							case 0
								temp2 = 0
								break
							case 1
								temp2 = 8
								break
							case 2
								temp2 = 16
								break
							case 3
								temp2 = 32
								break
							case 4
								temp2 = 64
								break
							case 5
								temp2 = 96
								break
							case 6
								temp2 = 128
								break
							case 7
								temp2 = 160
								break
						end switch
						break
					case 1	
						switch temp2
							case 0
								temp2 = 0
								break
							case 1
								temp2 = 9
								break
							case 2
								temp2 = 18
								break
							case 3
								temp2 = 36
								break
							case 4
								temp2 = 72
								break
							case 5
								temp2 = 108
								break
							case 6
								temp2 = 144
								break
							case 7
								temp2 = 180
								break
						end switch	
						break
					case 2	
						switch temp2
							case 0
								temp2 = 0
								break
							case 1	
								temp2 = 13
								break	
							case 2
								temp2 = 26
								break	
							case 3
								temp2 = 52
								break
							case 4
								temp2 = 87
								break
							case 5
								temp2 = 116
								break
							case 6
								temp2 = 144
								break
							case 7
								temp2 = 172
								break
						end switch
						break
					end switch	
					temp3 = temp2
					temp3 <<= 16				
					
					temp4 = temp2
					temp4 <<= 8
					
					temp5 = temp2	

					temp1 = temp3
					temp1 += temp4
					temp1 += temp5
					SetPaletteEntry(2, temp0, temp1)
					temp0++
				loop				
			end if				
			break
		case 5 // Language
			if inputPress.left == 1
				saved.language--
				if saved.language < 0
					saved.language = 3
				end if
				CallFunction(SetTextFileLanguage)				
			end if
			if inputPress.right == 1
				saved.language++
				if saved.language > 3
					saved.language = 0
				end if
				CallFunction(SetTextFileLanguage)				
			end if				
			break
		case 6 // VSync
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.vsync ^= 1
				CallNativeFunction2(SetWindowVSync, saved.vsync, 0)
			end if
			break
		case 7 // Scaling Mode
			if inputPress.left == 1					
				saved.scalemode--
				if saved.scalemode < 0
					saved.scalemode = 3
				end if
				CallNativeFunction2(SetWindowScaleMode, saved.scalemode, 0)
			end if
			if inputPress.right == 1
				saved.scalemode++
				if saved.scalemode > 3
					saved.scalemode = 0
				end if
				CallNativeFunction2(SetWindowScaleMode, saved.scalemode, 0)
			end if
			break
		case 8 // Refresh Rate
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				if saved.fps == 60
					saved.fps = 50
				else
					saved.fps = 60
				end if
				CallNativeFunction2(SetFrameRate, saved.fps, 0)
			end if
			break
		case 9 // Button Visability 
			if inputPress.left == 1			
				saved.transmobile--
				if saved.transmobile < 0
					saved.transmobile = 4
				end if
			end if
			if inputPress.right == 1
				saved.transmobile++
				if saved.transmobile > 4
					saved.transmobile = 0
				end if
			end if
			break
	end switch
end function


function display.draw
	// Fullscreen
	object.index = 81
	CallFunction(DrawOptionLeft)

	if saved.fullscreen == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// Aspect Ratio
	object.index = 82
	CallFunction(DrawOptionLeft)

	switch screen.xsize
	case 320
		object.index = 84
		break
	case 384
		object.index = 85
		break
	case 426
		object.index = 83
		break
	default
		object.index = 86
		break
	end switch
	CallFunction(DrawOptionRight)

	// Window Sacle
	object.index = 87
	CallFunction(DrawOptionLeft)

	object.index = saved.scale
	object.index += 87
	CallFunction(DrawOptionRight)

	// Graphics Mode
	object.index = 92
	CallFunction(DrawOptionLeft)

	object.index = saved.graphics
	object.index += 93
	CallFunction(DrawOptionRight)

	// language
	object.index = 96
	CallFunction(DrawOptionLeft)

	object.index = 97
	CallFunction(DrawOptionRight)

	// v stin
	object.index = 98
	CallFunction(DrawOptionLeft)

	if saved.vsync == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// v stin
	object.index = 99
	CallFunction(DrawOptionLeft)

	object.index = saved.scalemode
	object.index += 100
	CallFunction(DrawOptionRight)

	// frame rat
	object.index = 104
	CallFunction(DrawOptionLeft)

	if saved.fps == 60
		object.index = 105
	else
		if saved.fps == 50
			object.index = 106
		else
			object.index = 86
		end if
	end if	
	CallFunction(DrawOptionRight)

	if saved.mobile == 1
		// frame rat
		object.index = 217
		CallFunction(DrawOptionLeft)

		object.index = saved.transmobile
		object.index += 218
		CallFunction(DrawOptionRight)
	end if	
end function


function gameplay.menu
	CallFunction(main.sound)
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			object.currentSelection = 9
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if object.currentSelection > 9
				object.currentSelection = 0
			end if
		end if
	end if
	
	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		object.curMenu--
		object.state = 0
		object.currentSelection = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu++
			object.state = 0
			object.currentSelection = 0
		end if		
	end if

	switch object.currentSelection
		case 0 // Gameplay Highlighted
			break
		case 1 // Emeralds
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.superStates ^= 1
			end if
			break
		case 2 // Special Stage Rotation
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.specialSpin ^= 1
			end if
			break
		case 3 // Random Monitors
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.randomMonitor ^= 1
			end if
			break
		case 4 // Lives
			temp0 = inputPress.left
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.lives ^= 1
			end if
			break
		case 5 // Time Limit
			if inputPress.left == 1
				saved.timeLimit--
				if saved.timeLimit < 0
					saved.timeLimit = 2
				end if
			end if
			if inputPress.right == 1
				saved.timeLimit++
				if saved.timeLimit > 2
					saved.timeLimit = 0
				end if
			end if
			break
		case 6 // Ground Speed Cap highlighted
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.speedCap ^= 1
			end if
			break
		case 7 // Air Speed Cap Hightlighted
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.airSpeedCap ^= 1
			end if
			break
		case 8 // Roll Jump Lock
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Jumplock ^= 1
			end if
			break
		case 9 // Spike Bug Highlighted
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.spikeBehavior ^= 1
			end if
			break	
	end switch
end function


function gameplay.draw
	// Emeralds
	object.index = 107
	CallFunction(DrawOptionLeft)
	if saved.superStates == 1
		object.index = 109
	else
		object.index = 108
	end if
	CallFunction(DrawOptionRight)	


	// special stage rotation
	object.index = 110
	CallFunction(DrawOptionLeft)
	if saved.specialSpin == 1
		object.index = 112
	else
		object.index = 111
	end if
	CallFunction(DrawOptionRight)	

	// random
	object.index = 113
	CallFunction(DrawOptionLeft)

	if saved.randomMonitor == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// infinite
	object.index = 114
	CallFunction(DrawOptionLeft)

	if saved.lives == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// time
	object.index = 115
	CallFunction(DrawOptionLeft)

	switch saved.timeLimit 
	case 0
		object.index = 80
		break
	case 1
		object.index = 116
		break
	case 2
		object.index = 117
		break
	end switch
	CallFunction(DrawOptionRight)

	// cap ground
	object.index = 118
	CallFunction(DrawOptionLeft)

	if saved.speedCap == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// cap air
	object.index = 119
	CallFunction(DrawOptionLeft)

	if saved.airSpeedCap == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// cap air
	object.index = 120
	CallFunction(DrawOptionLeft)

	if saved.Jumplock == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// cap air
	object.index = 121
	CallFunction(DrawOptionLeft)

	if saved.spikeBehavior == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)
end function


function abilities.menu
	CallFunction(main.sound)
	temp0 = 9
	temp0 += saveRAM[417]
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			object.currentSelection = temp0
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if object.currentSelection > temp0
				object.currentSelection = 0
			end if
		end if
	end if

	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		object.curMenu--
		object.state = 0
		object.currentSelection = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu++
			object.state = 0
			object.currentSelection = 0
		end if		
	end if
	
	switch object.currentSelection
		case 0 //Abilities Highlighted
			break
		case 1 // Elemental
			temp0 = inputPress.left
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.elemental ^= 1
			end if
			break
		case 2 // SpinDash				
			if inputPress.left == 1
				saved.Spindash--
				if saved.Spindash < 0
					saved.Spindash = 2
					end if
			end if
			if inputPress.right == 1
				saved.Spindash++
				if saved.Spindash > 2
					saved.Spindash = 0
				end if
			end if
			break
		case 3 // InstaShield
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Instashield ^= 1
			end if
			break
		case 4 // Super Peel Out
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Peelout ^= 1
			end if
			break
		case 5 // Dropdash
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Dropdash ^= 1
			end if
			break
		case 6 // Bubble Shield
			temp0 = inputPress.left
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.bubble ^= 1
			end if
			break
		case 7 // Tails Flight Cancel
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.FlightCancel ^= 1
			end if
			break
		case 8 // Super Form Cancel
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Supercancel ^= 1
			end if
			break
		case 9 // Amy Moveset
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.AmyMoveset ^= 1
			end if
			break
		case 10 //GoGoPlus
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.gogoplus ^= 1
			end if
			break
	end switch
end function


function abilities.draw
	// random
	object.index = 122
	CallFunction(DrawOptionLeft)

	if saved.elemental == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// spindash
	object.index = 123
	CallFunction(DrawOptionLeft)
	switch saved.spindash
	case 0
		object.index = 80
		break
	case 1
		object.index = 124
		break
	case 2
		object.index = 125
		break
	end switch
	CallFunction(DrawOptionRight)

	// insta
	object.index = 126
	CallFunction(DrawOptionLeft)

	if saved.InstaShield == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// peel
	object.index = 127
	CallFunction(DrawOptionLeft)

	if saved.Peelout == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// drop
	object.index = 128
	CallFunction(DrawOptionLeft)

	if saved.Dropdash == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// drop
	object.index = 129
	CallFunction(DrawOptionLeft)

	if saved.bubble == 1
		object.index = 130
	else
		object.index = 131
	end if
	CallFunction(DrawOptionRight)

	// FlightCancel
	object.index = 132
	CallFunction(DrawOptionLeft)

	if saved.FlightCancel == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// FlightCancel
	object.index = 137
	CallFunction(DrawOptionLeft)

	if saved.Supercancel == 1
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// amy moveset
	object.index = 133
	CallFunction(DrawOptionLeft)

	if saved.AmyMoveset == 0
		object.index = 134
	else
		object.index = 135
	end if
	CallFunction(DrawOptionRight)

	if saveRAM[417] == 1
		// hyper
		object.index = 136
		CallFunction(DrawOptionLeft)

		if saved.gogoplus == 1
			object.index = 79
		else
			object.index = 80
		end if
		CallFunction(DrawOptionRight)		
	end if
end function


function visuals.menu
	CallFunction(main.sound)
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			object.currentSelection = 18
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if object.currentSelection > 18
				object.currentSelection = 0
			end if
		end if
	end if

	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		object.curMenu--
		object.state = 0
		object.currentSelection = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu++
			object.state = 0
			object.currentSelection = 0
		end if		
	end if
	
	switch object.currentSelection
		case 0 //Visuals Highlighted
			break
		case 1 // SHC Splash
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.beeToggle ^= 1
			end if
			break			
		case 2 // SPEEN
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				if saved.Speen == 1
					saved.Speen = 0
				else
					saved.Speen = 1
					temp7 = frame.count
					temp7 %= 50
					if temp7 == 0				
						speen.timer = 1
						PlaySfx(SfxName[Trigger], 0)
					end if
				end if
			end if
			break
		case 3 // Player Rotation
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.rotate ^= 1
			end if
			break
		case 4 // Shield Type
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.shieldType ^= 1
				saved.shieldType &= 1
			end if
			break
		case 5 // Invincibility Type
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.invincibilityType ^= 1
			end if
			break
		case 6 // Extended Timer
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Timer ^= 1
			end if
			break
		case 7 // Region
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.region ^= 1
			end if
			break
		case 8 // Green Hill Water Color

			if inputPress.left == 1
				saved.GHZwater--
				if saved.GHZwater < 0
					saved.GHZwater = 2
				end if
			end if
			if inputPress.right == 1
				saved.GHZwater++
				if saved.GHZwater > 2
					saved.GHZwater = 0
				end if
			end if
			break
		case 9 // UFOs
			if inputPress.left == 1
				saved.UFO--
				if saved.UFO < 0
					saved.UFO = 2
				end if
			end if
			if inputPress.right == 1
				saved.UFO++
				if saved.UFO > 2
					saved.UFO = 0
				end if
			end if
			break	
		case 10 // Sonic Max Dash
			if inputPress.left == 1
				saved.SonicMaxDash--
				if saved.SonicMaxDash < 0
					saved.SonicMaxDash  = 3
				end if
			end if
			if inputPress.right == 1
				saved.SonicMaxDash++
				if saved.SonicMaxDash > 3
					saved.SonicMaxDash = 0
				end if
			end if
			break	
		case 11 // Super Max Dash
			if inputPress.left == 1
				saved.SuperMaxDash--
				if saved.SuperMaxDash < 0
					saved.SuperMaxDash  = 2
				end if
			end if
			if inputPress.right == 1
				saved.SuperMaxDash++
				if saved.SuperMaxDash > 2
					saved.SuperMaxDash = 0
				end if
			end if
			break				
		case 12 // Tails Max Dash
			if inputPress.left == 1
				saved.TailsMaxDash--
				if saved.TailsMaxDash < 0
					saved.TailsMaxDash  = 2
				end if
			end if
			if inputPress.right == 1
				saved.TailsMaxDash++
				if saved.TailsMaxDash > 2
					saved.TailsMaxDash = 0
				end if
			end if
			break		
		case 13 // Knux Max Dash
			if inputPress.left == 1
				saved.KnuxMaxDash--
				if saved.KnuxMaxDash < 0
					saved.KnuxMaxDash  = 2
				end if
			end if
			if inputPress.right == 1
				saved.KnuxMaxDash++
				if saved.KnuxMaxDash > 2
					saved.KnuxMaxDash = 0
				end if
			end if
			break
		case 14 // Amy Max Dash
			if inputPress.left == 1
				saved.AmyMaxDash--
				if saved.AmyMaxDash < 0
					saved.AmyMaxDash  = 2
				end if
			end if
			if inputPress.right == 1
				saved.AmyMaxDash++
				if saved.AmyMaxDash > 2
					saved.AmyMaxDash = 0
				end if
			end if
			break	
		case 15 // Sayori Max Dash
			if inputPress.left == 1
				saved.SayoriMaxDash--
				if saved.SayoriMaxDash < 0
					saved.SayoriMaxDash  = 1
				end if
			end if
			if inputPress.right == 1
				saved.SayoriMaxDash++
				if saved.SayoriMaxDash > 1
					saved.SayoriMaxDash = 0
				end if
			end if
			break
		case 16 // Natsuki Max Dash
			if inputPress.left == 1
				saved.NatsukiMaxDash--
				if saved.NatsukiMaxDash < 0
					saved.NatsukiMaxDash  = 1
				end if
			end if
			if inputPress.right == 1
				saved.NatsukiMaxDash++
				if saved.NatsukiMaxDash > 1
					saved.NatsukiMaxDash = 0
				end if
			end if
			break
		case 17 // Yuri Max Dash
			if inputPress.left == 1
				saved.YuriMaxDash--
				if saved.YuriMaxDash < 0
					saved.YuriMaxDash  = 1
				end if
			end if
			if inputPress.right == 1
				saved.YuriMaxDash++
				if saved.YuriMaxDash > 1
					saved.YuriMaxDash = 0
				end if
			end if
			break
		case 18 // Monika Max Dash
			if inputPress.left == 1
				saved.MonikaMaxDash--
				if saved.MonikaMaxDash < 0
					saved.MonikaMaxDash  = 1
				end if
			end if
			if inputPress.right == 1
				saved.MonikaMaxDash++
				if saved.MonikaMaxDash > 1
					saved.MonikaMaxDash = 0
				end if
			end if
			break
	end switch
end function


function visuals.draw

	// bees
	object.index = 212
	CallFunction(DrawOptionLeft)

	if saved.beeToggle == 0
		object.index = 79
	else
		object.index = 80
	end if
	CallFunction(DrawOptionRight)

	// I LOVE YOU SPEEN
	object.index = 138
	CallFunction(DrawOptionLeft)

	if saved.Speen == 1
		object.index = 125
	else
		object.index = 142
	end if
	CallFunction(DrawOptionRight)

	// rotat
	object.index = 139
	CallFunction(DrawOptionLeft)

	if saved.rotate == 1
		object.index = 130
	else
		object.index = 111
	end if
	CallFunction(DrawOptionRight)

	// shield
	object.index = 140
	CallFunction(DrawOptionLeft)

	if saved.shieldType == 1
		object.index = 124
	else
		object.index = 142
	end if
	CallFunction(DrawOptionRight)

	// invicbnlt
	object.index = 141
	CallFunction(DrawOptionLeft)

	if saved.invincibilityType == 1
		object.index = 124
	else
		object.index = 142
	end if
	CallFunction(DrawOptionRight)

	// invicbnlt
	object.index = 143
	CallFunction(DrawOptionLeft)

	if saved.timer == 1
		object.index = 144
	else
		object.index = 145
	end if
	CallFunction(DrawOptionRight)

	// invicbnlt
	object.index = 146
	CallFunction(DrawOptionLeft)

	if saved.region == 1
		object.index = 148
	else
		object.index = 147
	end if
	CallFunction(DrawOptionRight)

	// invicbnlt
	object.index = 149
	CallFunction(DrawOptionLeft)

	switch saved.GHZwater
	case 0
		object.index = 111
		break
	case 2
		object.index = 150
		break
	case 1
		object.index = 134
		break
	end switch

	CallFunction(DrawOptionRight)

	// invicbnlt
	object.index = 151
	CallFunction(DrawOptionLeft)

	switch saved.UFO
	case 0
		object.index = 80
		break
	case 1
		object.index = 153
		break
	case 2
		object.index = 152
		break
	end switch

	CallFunction(DrawOptionRight)

	// sonic max
	object.index = 156
	CallFunction(DrawOptionLeft)

	switch saved.SonicMaxDash
	case 0
		object.index = 80
		break
	case 1
		object.index = 125
		break
	case 2
		object.index = 154
		break
	case 3
		object.index = 130
		break
	end switch

	CallFunction(DrawOptionRight)

	// sonic max
	object.index = 157
	CallFunction(DrawOptionLeft)

	switch saved.SuperMaxDash
	case 0
		object.index = 80
		break
	case 2
		object.index = 130
		break
	case 1
		object.index = 155
		break
	end switch

	CallFunction(DrawOptionRight)

	// tails max
	object.index = 158
	CallFunction(DrawOptionLeft)

	switch saved.TailsMaxDash
	case 0
		object.index = 80
		break
	case 1
		object.index = 124
		break
	case 2
		object.index = 134
		break
	end switch

	CallFunction(DrawOptionRight)

	// knux max
	object.index = 159
	CallFunction(DrawOptionLeft)

	switch saved.KnuxMaxDash
	case 0
		object.index = 80
		break
	case 1
		object.index = 155
		break
	case 2
		object.index = 130
		break
	end switch

	CallFunction(DrawOptionRight)

	// amy max
	object.index = 160
	CallFunction(DrawOptionLeft)

	switch saved.AmyMaxDash
	case 0
		object.index = 80
		break
	case 1
		object.index = 165
		break
	case 2
		object.index = 134
		break
	end switch

	CallFunction(DrawOptionRight)

	// sayori max toggle
	object.index = 161
	CallFunction(DrawOptionLeft)

	if saved.SayoriMaxDash == 1
		object.index = 79
	else
		object.index = 80
	end if

	CallFunction(DrawOptionRight)

	// natsuki max toggle
	object.index = 162
	CallFunction(DrawOptionLeft)

	if saved.NatsukiMaxDash == 1
		object.index = 79
	else
		object.index = 80
	end if

	CallFunction(DrawOptionRight)

	// yuri max toggle
	object.index = 163
	CallFunction(DrawOptionLeft)

	if saved.YuriMaxDash == 1
		object.index = 79
	else
		object.index = 80
	end if

	CallFunction(DrawOptionRight)

	// monika max toggle
	object.index = 164
	CallFunction(DrawOptionLeft)

	if saved.MonikaMaxDash == 1
		object.index = 79
	else
		object.index = 80
	end if

	CallFunction(DrawOptionRight)
end function	


function sound.menu
	CallFunction(main.sound)
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			object.currentSelection = 6
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if object.currentSelection > 6
				object.currentSelection = 0
			end if
		end if
	end if

	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		object.curMenu--
		object.state = 0
		object.currentSelection = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu++
			object.state = 0
			object.currentSelection = 0
		end if		
	end if
	
	switch object.currentSelection
		case 0 //Sound Highlighted
			break
		case 1 // Music Volume
			if inputPress.left == 1
				temp0 = Engine.BGMVolume
				temp0 -= 10
				if temp0 < 0
					temp0 = 0
				end if
				Engine.BGMVolume = temp0
			end if
			if inputPress.right == 1
				temp0 = Engine.BGMVolume
				temp0 += 10
				if temp0 > 100
					temp0 = 100
				end if
				Engine.BGMVolume = temp0
			end if
			break
		case 2 // SFX Volume
			if inputPress.left == 1
				temp0 = Engine.SFXVolume
				temp0 -= 10
				if temp0 < 0
					temp0 = 0
				end if
				Engine.SFXVolume = temp0
			end if
			if inputPress.right == 1
				temp0 = Engine.SFXVolume
				temp0 += 10
				if temp0 > 100
					temp0 = 100
				end if
				Engine.SFXVolume = temp0
			end if
			break
		case 3 // Drowning Music
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.Drowning ^= 1
			end if
			break
		case 4 // Super Music
			if inputPress.left == 1
				saved.Supermusic--
				if saved.Supermusic < 0
					saved.Supermusic = 7
				end if
			end if
			if inputPress.right == 1
				saved.Supermusic++
				if saved.Supermusic > 7
					saved.Supermusic = 0
				end if
			end if
			break				
		case 5 // doki Music
			if inputPress.left == 1
				saved.dokiTracks--
				if saved.dokiTracks < 0
					saved.dokiTracks = 2
				end if
			end if
			if inputPress.right == 1
				saved.dokiTracks++
				if saved.dokiTracks > 2
					saved.dokiTracks = 0
				end if
			end if
			break				
		case 6 // menu Music
			if inputPress.left == 1
				saved.dokiMenuMusic--
				if saved.dokiMenuMusic < 0
					saved.dokiMenuMusic = 3
				end if
			end if
			if inputPress.right == 1
				saved.dokiMenuMusic++
				if saved.dokiMenuMusic > 3
					saved.dokiMenuMusic = 0
				end if
			end if
			break				
	end switch
end function


function sound.draw
	// mui
	object.index = 166
	CallFunction(DrawOptionLeft)

	if saved.mobile == 0
		object.index = 170
		temp0 = Engine.BGMVolume
		temp0 /= 10
		object.index += temp0

		object.drawPos.y += optionYSpace	
		//CallFunction(DrawOptionRight)

		temp0 = object.rightPartX
		temp0 -= 105
		temp1 = object.drawPos.y
		temp1 -= 11
		DrawRect(temp0, temp1, 105, 1, 0, 0, 0, object[arrayPos0].alpha)
		object.inkEffect = INK_ALPHA
		object.alpha = object[arrayPos0].alpha
		temp0 += Engine.BGMVolume
		temp0 -= 5
		DrawSpriteScreenFX(224, FX_INK, temp0, temp1)
		object.inkEffect = INK_NONE	
		object.menuLine++
		arrayPos0++
		arrayPos1++		
	else
		object.index = 170
		temp0 = Engine.BGMVolume
		temp0 /= 10
		object.index += temp0

		CallFunction(DrawOptionRight)			
	end if	


	// sfx
	object.index = 167
	CallFunction(DrawOptionLeft)

	if saved.mobile == 0
		object.index = 170
		temp0 = Engine.SFXVolume
		temp0 /= 10
		object.index += temp0

		object.drawPos.y += optionYSpace	
		//CallFunction(DrawOptionRight)

		temp0 = object.rightPartX
		temp0 -= 105
		temp1 = object.drawPos.y
		temp1 -= 11
		DrawRect(temp0, temp1, 105, 1, 0, 0, 0, object[arrayPos0].alpha)
		object.inkEffect = INK_ALPHA
		object.alpha = object[arrayPos0].alpha
		temp0 += Engine.SFXVolume
		temp0 -= 5
		DrawSpriteScreenFX(224, FX_INK, temp0, temp1)
		object.inkEffect = INK_NONE	
		object.menuLine++
		arrayPos0++
		arrayPos1++		
	else
		object.index = 170
		temp0 = Engine.SFXVolume
		temp0 /= 10
		object.index += temp0

		CallFunction(DrawOptionRight)			
	end if	

	// drown
	object.index = 168
	CallFunction(DrawOptionLeft)

	if saved.Drowning == 1
		object.index = 125
	else
		object.index = 142
	end if

	CallFunction(DrawOptionRight)

	// super music
	object.index = 169
	CallFunction(DrawOptionLeft)
	
	switch saved.Supermusic
	case 0
		object.index = 80
		break
	case 1
		object.index = 124
		break
	case 2
		object.index = 131
		break	
	case 3
		object.index = 181
		break	
	case 5
		object.index = 130
		break	
	case 4
		object.index = 182
		break	
	case 6
		object.index = 183
		break	
	case 7
		object.index = 184
		break	
	end switch

	CallFunction(DrawOptionRight)

	// ddlc mix
	object.index = 198
	CallFunction(DrawOptionLeft)

	switch saved.dokiTracks
	case 0
		object.index = 80
		break
	case 1
		object.index = 79
		break
	case 2
		object.index = 199
		break
	end switch

	CallFunction(DrawOptionRight)

	// ddlc mix
	object.index = 213
	CallFunction(DrawOptionLeft)

	switch saved.dokiMenuMusic
	case 1
		object.index = 215
		break
	case 0
		object.index = 214
		break
	case 2
		object.index = 111
		break
	case 3
		object.index = 134
		break
	end switch

	CallFunction(DrawOptionRight)
end function

function datamang.menu
	CallFunction(main.sound)
	switch deleteCheck
	case 0 
		if inputPress.up == 1
			object.currentSelection--
			if object.currentSelection < 0
				object.currentSelection = 9
			end if
		else	
			if inputPress.down == 1
				object.currentSelection++
				if object.currentSelection > 9
					object.currentSelection = 0
				end if
			end if
		end if

		CheckEqual(inputPress.buttonL, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.left, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu--
			object.currentSelection = 0
			object.state = 0
		else
			CheckEqual(inputPress.buttonR, 1)
			temp0 = checkResult
			if object.currentSelection == 0
				CheckEqual(inputPress.right, 1)
				temp0 |= checkResult
			end if
			if temp0 == 1
				if enableModOption == 1
					object.curMenu = 6
				else
					object.curMenu = 0
				end if	
				object.state = 0
				object.currentSelection = 0
			end if		
		end if

		if object.currentSelection > 0
			temp0 = inputPress.buttonA
			temp0 |= inputPress.start
			if temp0 == 1
				PlaySfx(SfxName[Select], false)
				deleteCheck = 1
				object.deleteSelect = 1
			end if
		end if	
		break
	case 1	
		temp1 = 0

		temp0 = screen.xcenter
		temp0 -= 42
		temp4 = temp0
		temp4 += 23
		temp2 = screen.ycenter
		temp2 += 10
		temp3 = temp2
		temp3 += 11
		CheckTouchRect(temp0, temp2, temp4, temp3)

		if checkResult > -1
			temp1 = 1
			PlaySfx(SfxName[Select], false)
		end if	

		temp0 = screen.xcenter
		temp0 += 20
		temp4 = temp0
		temp4 += 20
		temp2 = screen.ycenter
		temp2 += 10
		temp3 = temp2
		temp3 += 11
		CheckTouchRect(temp0, temp2, temp4, temp3)
		if checkResult > -1
			temp1 = 2
			PlaySfx(SfxName[Select], false)
		end if			

		temp0 = inputPress.left
		temp0 |= inputPress.right
		if temp0 == 1
			object.deleteSelect ^= 1
		end if
		temp0 = inputPress.buttonA
		temp0 |= inputPress.start
		if temp0 == 1
			PlaySfx(SfxName[Select], false)
			deleteCheck = 2
			temp1 = object.deleteSelect
			temp1++
		end if	
		if inputPress.buttonB == 1
			temp1 = 2
		end if	
		if temp1 > 0
			deleteCheck = 0
			switch temp1
			case 1
				switch object.currentSelection
				case 1
					CallFunction(option.restore)
					break
				case 2
					CallFunction(delete.save)
					CallFunction(delete.ta)
					CallFunction(delete.arcade)
					CallFunction(delete.golf)
					CallFunction(delete.extras)
					CallFunction(delete.achieve)
					CallFunction(delete.secret)
					break
				case 3
					CallFunction(delete.save)
					break
				case 4
					CallFunction(delete.ta)
					break
				case 5
					CallFunction(delete.arcade)
					break
				case 6
					CallFunction(delete.golf)
					break
				case 7
					CallFunction(delete.extras)
					break
				case 8
					CallFunction(delete.achieve)
					break
				case 9
					CallFunction(delete.secret)
					break
				end switch
				break
			case 2
				// nothing tbh
				break
			end switch
		end if	
		break
	end switch	
end function


function datamang.draw
	temp7 = 0
	
	while temp7 < 9
		object.index = temp7
		object.index += 186
		CallFunction(DrawDataOption)
		temp7++
	loop

	if deleteCheck == 1
		// pop up
		DrawRect(0, 0, screen.xsize, screen.ysize, color7, color7, color7, 120)
		temp0 = 196
		temp1 = 60
		temp2 = temp0
		temp2 /= 2
		FlipSign(temp2)	
		temp2 += screen.xcenter
		temp3 = temp1
		temp3 /= 2
		FlipSign(temp3)
		temp3 += screen.ycenter
		DrawRect(temp2, temp3, temp0, temp1, color7, color5, color6, 255)
		temp2++	
		temp3++
		temp0 -= 2	
		temp1 -= 2
		DrawRect(temp2, temp3, temp0, temp1, color7, color5, color6, 255)	
		DrawRect(temp2, temp3, temp0, temp1, color7, color7, color7, 180)	

		object.index = 195
		object.fontSize = FONT_TINY
		object.drawPos.x = screen.xcenter
		object.drawPos.y = screen.ycenter
		object.drawPos.y -= 10
		object.textCenterIt = 1
		object.menuLine = -10
		CallFunction(Options_DrawTextString)

		object.index = 196
		object.fontSize = FONT_SMALL
		object.drawPos.x = screen.xcenter
		object.drawPos.x -= 30
		object.drawPos.y = screen.ycenter
		object.drawPos.y += 10
		object.textCenterIt = 1
		object.menuLine = -11
		CallFunction(Options_DrawTextString)

		object.index = 197
		object.fontSize = FONT_SMALL
		object.drawPos.x = screen.xcenter
		object.drawPos.x += 30		
		object.drawPos.y = screen.ycenter
		object.drawPos.y += 10
		object.textCenterIt = 1
		object.menuLine = -12
		CallFunction(Options_DrawTextString)

		MenuBackButton = true
	end if
end function


function modOptions.menu
	CallFunction(main.sound)
	if inputPress.up == 1
		object.currentSelection--
		if object.currentSelection < 0
			object.currentSelection = 4
		end if
	else	
		if inputPress.down == 1
			object.currentSelection++
			if object.currentSelection > 4
				object.currentSelection = 0
			end if
		end if
	end if
	
	CheckEqual(inputPress.buttonL, 1)
	temp0 = checkResult
	if object.currentSelection == 0
		CheckEqual(inputPress.left, 1)
		temp0 |= checkResult
	end if
	if temp0 == 1
		object.curMenu--
		object.state = 0
		object.currentSelection = 0
	else
		CheckEqual(inputPress.buttonR, 1)
		temp0 = checkResult
		if object.currentSelection == 0
			CheckEqual(inputPress.right, 1)
			temp0 |= checkResult
		end if
		if temp0 == 1
			object.curMenu = 0
			object.state = 0
			object.currentSelection = 0
		end if		
	end if

	switch object.currentSelection
		case 0 //Sound Highlighted
			break
		case 1 // Lamp Style
			if saveRAM[416] == 1
				temp0 = 11
			else
				temp0 = 10
			end if

			if inputPress.left == 1
				saved.lampStyle--
				if saved.lampStyle < 0
					saved.lampStyle = temp0
				end if
			end if
			if inputPress.right == 1
				saved.lampStyle++
				if saved.lampStyle > temp0
					saved.lampStyle = 0
				end if
			end if
			break
		case 2 // SFX Volume
			if inputPress.left == 1
				saved.bulbStyle--
				if saved.bulbStyle < 0
					saved.bulbStyle = 7
				end if
			end if
			if inputPress.right == 1
				saved.bulbStyle++
				if saved.bulbStyle > 7
					saved.bulbStyle = 0
				end if
			end if
			break
		case 3 // Drowning Music
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.bulbYellow ^= 1
			end if
			break
		case 4 // Super Music
			temp0 = inputPress.left
			temp0 |= inputPress.right
			if temp0 == 1
				saved.sonic2entrance ^= 1
			end if
			break				
	end switch
end function


function modOptions.draw
	object.index = 201
	CallFunction(DrawOptionLeft)

	switch saved.lampStyle
	case 0
		object.index = 142
		break
	case 1
		object.index = 125
		break	
	case 2
		object.index = 206
		break	
	case 3
		object.index = 207
		break	
	case 4
		object.index = 208
		break	
	case 5
		object.index = 124
		break	
	case 6
		object.index = 131
		break	
	case 7
		object.index = 130
		break	
	case 8
		object.index = 209
		break	
	case 9
		object.index = 210
		break	
	case 10
		object.index = 211
		break	
	case 11
		object.index = 205
		break	
	end switch
	CallFunction(DrawOptionRight)

	object.index = 202
	CallFunction(DrawOptionLeft)

	switch saved.bulbStyle
	case 0
		object.index = 134
		break
	case 1
		object.index = 111
		break	
	case 2
		object.index = 124
		break	
	case 3
		object.index = 209
		break	
	case 4
		object.index = 208
		break	
	case 5
		object.index = 130
		break
	case 6
		object.index = 210
		break	
	case 7
		object.index = 211
		break				
	end switch
	CallFunction(DrawOptionRight)

	object.index = 203
	CallFunction(DrawOptionLeft)

	switch saved.bulbYellow
	case 0
		object.index = 80
		break
	case 1
		object.index = 79
		break		
	end switch
	CallFunction(DrawOptionRight)

	object.index = 204
	CallFunction(DrawOptionLeft)

	switch saved.sonic2entrance
	case 0
		object.index = 142
		break
	case 1
		object.index = 124
		break		
	end switch
	CallFunction(DrawOptionRight)
end function


event ObjectMain
	if object.propertyValue == 0
		if MenuBackButton == true
			CheckTouchRect(8, 8, 32, 32)
			
			if checkResult > -1
				if object[1].touchSfxDelay == false
					inputPress.buttonB = 1

					PlaySfx(SfxName[Hover], false)
					object[1].touchSfxDelay = true
				end if
			else
				object[1].touchSfxDelay = false		
			end if						
		end if	

		if object.state == 0
			arrayPos0 = 40
			arrayPos1 = 80
			temp1 = 0
			while temp1 < 20
				ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Options], 1, 0, 0)
				ResetObjectEntity(object[arrayPos1].entityPos, TypeName[Options], 1, 0, 0)
				object[arrayPos0].drawOrder = 0
				object[arrayPos1].drawOrder = 0
				object[arrayPos0].priority = PRIORITY_ACTIVE
				object[arrayPos1].priority = PRIORITY_ACTIVE
				temp2 = -10
				temp2 *= temp1
				object[arrayPos0].alpha = temp2
				object[arrayPos0].value40 = 256
				object[arrayPos0].state = 0							
				object[arrayPos1].alpha = temp2
				object[arrayPos1].value40 = 256
				object[arrayPos1].state = 0					
				arrayPos0++
				arrayPos1++
				temp1++
			loop			
			object.state++
		else
			if saved.mobile == 1
				switch optionCheck
				case 0
					if object.currentSelection > 0
						inputPress.left = 0	
						inputPress.right = 0
						temp0 = inputPress.buttonA
						temp0 |= inputPress.start
						if temp0 == 1
							PlaySfx(SfxName[Select], false)
							optionCheck = 1
						end if
					end if	
					break
				case 1	
					inputPress.up = 0	
					inputPress.down = 0		
					temp0 = inputPress.buttonA
					temp0 |= inputPress.start
					temp0 |= inputPress.buttonB
					if temp0 == 1
						PlaySfx(SfxName[Select], false)
						optionCheck = 0
					end if					
					break
				end switch
			end if			
		end if	

		if saved.mobile == 1
			if optionCheck == 1
				object.drawPos.x = screen.xcenter
				object.drawPos.y = screen.ycenter
				object.drawPos.y -= 10

				temp0 = object.drawPos.x
				temp0 -= 90
				temp1 = temp0
				temp1 += 20
				temp2 = object.drawPos.y
				temp3 = temp2
				temp3 += 28
				CheckTouchRect(temp0, temp2, temp1, temp3)	
				if checkResult > -1
					if object[4].touchSfxDelay == false
						inputPress.left = 1		

						PlaySfx(SfxName[Hover], false)
						object[4].touchSfxDelay = true
					end if
				else
					object[4].touchSfxDelay = false		
				end if	

				temp0 = object.drawPos.x
				temp0 += 90
				temp1 = temp0
				temp1 -= 20
				CheckTouchRect(temp1, temp2, temp0, temp3)	
				if checkResult > -1
					if object[5].touchSfxDelay == false
						inputPress.right = 1		

						PlaySfx(SfxName[Hover], false)
						object[5].touchSfxDelay = true
					end if
				else
					object[5].touchSfxDelay = false		
				end if	
			end if	
		end if	
		switch object.curMenu
		case 0
			CallFunction(display.menu)	
			break
		case 1
			CallFunction(gameplay.menu)	
			break
		case 2
			CallFunction(abilities.menu)	
			break
		case 3
			CallFunction(visuals.menu)	
			break
		case 4
			CallFunction(sound.menu)	
			break
		case 5
			CallFunction(datamang.menu)	
			break
		case 6
			CallFunction(modOptions.menu)	
			break
		end switch

		frame.count++
		if frame.count >= 10800
			frame.count = 0
		end if	

		if object.currentSelection == 0
			if object.alphaArrows < 255
				object.alphaArrows += 55
			else
				object.alphaArrows = 255
			end if
		else			
			if object.alphaArrows > 0
				object.alphaArrows -= 55
			else
				object.alphaArrows = 0
			end if
		end if
		CallNativeFunction2(13, 0, "Data/Sprites/Global/Checkpoint.gif")
		enableModOption = checkResult	
	end if
	if saved.mobile == 1
		optionYSpace = 22
	else
		optionYSpace = 16
	end if			
end event


event ObjectDraw
	if object.propertyValue == 0
		// settings
		object.index = 3
		object.fontSize = FONT_SMALL
		object.drawPos.x = 15
		if screen.xsize == 320
			object.drawPos.x += 132
			object.drawPos.x += object[33].value7		
		end if	
		object.drawPos.y = 10
		object.textCenterIt = 0
		object.menuLine = -1
		CallFunction(Options_DrawTextString)

		MenuBackButton = false

		// option page
		if object.curMenu == 6
			object.index = 200
		else
			object.index = object.curMenu		
			object.index += 73
		end if		
		object.fontSize = FONT_LARGE
		object.drawPos.x = screen.xcenter
		if screen.xsize > 320
			object.drawPos.x += 53
		else
			object.drawPos.x += 132
			object.drawPos.x += object[33].value7							
		end if	
		object.drawPos.y = 30
		object.textCenterIt = 1
		object.menuLine = 0
		if object.currentSelection == 0
			CopyPalette(0, 149, 0, 50, 1)	
		end if	
		if saved.mobile == 0
			object.inkEffect = INK_ALPHA	
			object.alpha = object.alphaArrows
		end if	
		DrawSpriteScreenFX(226, FX_INK, object.drawPos.x, object.drawPos.y)
		DrawSpriteScreenFX(227, FX_INK, object.drawPos.x, object.drawPos.y)
		object.inkEffect = INK_NONE	
		CopyPalette(0, 171, 0, 50, 1)	

		CallFunction(Options_DrawTextString)
		if saved.mobile == 1
			if deleteCheck == 0
				if optionCheck == 0
					temp0 = object.drawPos.x
					temp0 -= 90
					temp1 = temp0
					temp1 += 180
					temp2 = object.drawPos.y
					temp3 = temp2
					temp3 += 28
					CheckTouchRect(temp0, temp2, temp1, temp3)
					if checkResult > -1
						object.currentSelection = 0
						if object.touchSfxDelay == false
							PlaySfx(SfxName[Hover], false)
							object.touchSfxDelay = true
						end if
					else
						object.touchSfxDelay = false		
					end if		

					temp0 = object.drawPos.x
					temp0 += 100
					temp0 -= 10
					temp1 = temp0
					temp1 += 20

					CheckTouchRect(temp0, temp2, temp1, temp3)
					if checkResult > -1
						if object[0].touchSfxDelay == false
							if enableModOption == 1
								temp5 = 6
							else
								temp5 = 5
							end if					
							if object.curMenu < temp5
								object.curMenu++
							else
								object.curMenu = 0
							end if	
							object.state = 0
							object.currentSelection = 0				

							PlaySfx(SfxName[Hover], false)
							object[0].touchSfxDelay = true
						end if
					else
						object[0].touchSfxDelay = false		
					end if	

					temp0 = object.drawPos.x
					temp0 -= 100
					temp0 -= 10
					temp1 = temp0
					temp1 += 20

					CheckTouchRect(temp0, temp2, temp1, temp3)
					if checkResult > -1
						if object[1].touchSfxDelay == false
							if object.curMenu > 0
								object.curMenu--
							else
								if enableModOption == 1
									object.curMenu = 6
								else
									object.curMenu = 5
								end if	
							end if	
							object.state = 0
							object.currentSelection = 0

							PlaySfx(SfxName[Hover], false)
							object[1].touchSfxDelay = true
						end if
					else
						object[1].touchSfxDelay = false		
					end if	
				end if	
			end if	
		end if		

		// draw all of them
		object.rightPartX = screen.xsize		
		if screen.xsize > 320
			object.leftPartX = 106
		else
			object.leftPartX = 132
			object.leftPartX += object[33].value7
			object.rightPartX += 132
			object.rightPartX += object[33].value7
		end if

		object.rightPartX -= 9
		object.leftPartX += 8
		object.drawPos.y = 60
		object.menuLine++

		arrayPos0 = object.menuLine
		arrayPos0 += 80	
		arrayPos1 = object.menuLine
		arrayPos1 += 40	

		optionMobileDrawerHelper = 0
		switch object.curMenu
		case 0
			CallFunction(display.draw)	
			break
		case 1
			CallFunction(gameplay.draw)	
			break
		case 2
			CallFunction(abilities.draw)	
			break
		case 3
			CallFunction(visuals.draw)	
			break
		case 4
			CallFunction(sound.draw)	
			break
		case 5
			CallFunction(datamang.draw)	
			break
		case 6
			CallFunction(modOptions.draw)	
			break
		end switch

		if object.curMenu != 5
			if optionCheck == 1
				// pop up
				DrawRect(0, 0, screen.xsize, screen.ysize, color7, color7, color7, 120)
				temp0 = 196
				temp1 = 60
				temp2 = temp0
				temp2 /= 2
				FlipSign(temp2)	
				temp2 += screen.xcenter
				temp3 = temp1
				temp3 /= 2
				FlipSign(temp3)
				temp3 += screen.ycenter
				DrawRect(temp2, temp3, temp0, temp1, color7, color5, color6, 255)
				temp2++	
				temp3++
				temp0 -= 2	
				temp1 -= 2
				DrawRect(temp2, temp3, temp0, temp1, color7, color5, color6, 255)	
				DrawRect(temp2, temp3, temp0, temp1, color7, color7, color7, 180)	

				object.index = 216
				object.fontSize = FONT_TINY
				object.drawPos.x = screen.xcenter
				object.drawPos.y = screen.ycenter
				object.drawPos.y -= 10
				object.textCenterIt = 1
				object.menuLine = -10
						
				DrawSpriteScreenXY(228, object.drawPos.x, object.drawPos.y)
				DrawSpriteScreenXY(229, object.drawPos.x, object.drawPos.y)				
				CallFunction(Options_DrawTextString)

				object.menuLine = 1

				arrayPos0 = object.menuLine
				arrayPos0 += 80	
				arrayPos1 = object.menuLine
				arrayPos1 += 40	
				optionMobileDrawerHelper = 1
				switch object.curMenu
				case 0
					CallFunction(display.draw)	
					break
				case 1
					CallFunction(gameplay.draw)	
					break
				case 2
					CallFunction(abilities.draw)	
					break
				case 3
					CallFunction(visuals.draw)	
					break
				case 4
					CallFunction(sound.draw)	
					break
				case 5
					CallFunction(datamang.draw)	
					break
				case 6
					CallFunction(modOptions.draw)	
					break
				end switch
				MenuBackButton = true
			end if
		end if

		if speen.timer == 1
			temp0 = speen.x
			temp0 -= 60
			DrawSpriteScreenXY(160, temp0, screen.ycenter)
			speen.x += 8
			temp0 -= 60
			if temp0 > screen.xsize
				speen.timer = 0
			end if
		else
			speen.x = 0
		end if

		if saved.mobile == 0
			if object.currentSelection <= 10
				scroll.max = 0
				scroll.min = 0
			else
				temp0 = object.currentSelection
				temp0 *= 7
				temp0 += 7
				scroll.max = temp0
				scroll.min = temp0
				scroll.min -= 24
			end if
		else
			if object.currentSelection <= 6
				scroll.max = 0
				scroll.min = 0
			else		
				temp0 = object.currentSelection
				temp0 *= 11
				temp0 += 11
				scroll.max = temp0
				scroll.min = temp0
				scroll.min -= optionYSpace
				//scroll.min += 14
			end if	
		end if	
		
		if scroll.current < scroll.min
			scroll.current += 4
		else
			if scroll.current > scroll.max
				scroll.current -= 4
			end if
		end if

		if saved.mobile == true
			if MenuBackButton == true
				//DrawSpriteScreenXY(230, 20, temp0)
				object.alpha = 230
				object.inkEffect = INK_ALPHA

				DrawSpriteScreenXY(230, 20, 20)
				SetActivePalette(3, 0, 256)
				DrawSpriteScreenFX(230, FX_INK, 20, 20)
				SetActivePalette(0, 0, 256)				
				DrawSpriteScreenFX(231, FX_INK, 20, 20)			
				DrawSpriteScreenXY(232, 20, 20)								
			end if
		end if
	else	

		temp0 = 0	
		if saved.mobile == 1
			if object.propertyValue == 1
				temp0 = 1		
			end if
		else
			temp0 = 1		
		end if
		if temp0 == 1
			object.inkEffect = INK_ALPHA	
			object.drawPos.y -= scroll[OPTIONS_SLOT].current		
			switch object.state
			case 0
				object.alpha += 20	
				if object.alpha > 250
					object.state++
				end if
				break
			case 1
				if object.drawPos.y < 52
					object.value40 = object.drawPos.y
					object.value40 *= 2
					object.value40 -= 110			
				else
					object.value40 = 256
				end if	
				temp1 = object.value40
				temp1 -= object.alpha
				temp1 >>= 1
				temp1 += 3
				object.alpha += temp1			
				break
			end switch
		else
			object.alpha = 256
			object.drawPos.y = screen.ycenter
			object.drawPos.y += 10
		end if	


		switch object[OPTIONS_SLOT].curMenu
		case 0
			temp0 = 9
			break
		case 1
			temp0 = 9
			break
		case 2
			temp0  = 9
			temp0 += saveRAM[417]
			break
		case 3
			temp0 = 18
			break
		case 4
			temp0 = 6
			break
		case 5
			temp0 = 9
			break
		case 6
			temp0 = 4
			break	
		end switch			
		if object.menuLine <= temp0
			if object.index > 0
				CallFunction(Options_DrawTextString)
			end if	
		end if		
	end if	
end event


event ObjectStartup
	CallNativeFunction(GetWindowScale)
	saved.scale = checkResult
	CallNativeFunction(GetWindowFullScreen)
	saved.fullscreen = checkResult
	CallNativeFunction(GetWindowVSync)
	saved.vsync = checkResult
	CallNativeFunction(GetWindowScaleMode)
	saved.scalemode = checkResult
	CallNativeFunction(GetFrameRate)
	saved.fps = checkResult

	LoadSpriteSheet("DDLCMenu/Menu.gif")
	SpriteFrame(0, 0, 0, 0, 0, 0) // 0 Blank
	
	//Uppercase
	temp0 = 0
	temp2 = 78
	temp3 = 242
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 15, 12, temp2, temp3) 1-26
			temp1++
			temp2 += 16
		loop
		temp2 = 78
		temp0++
		temp3 += 13
	loop

	SpriteFrame(-8, 0, 4, 4, 236, 116) 27

	//Lowercase
	temp0 = 0
	temp2 = 78
	temp3 = 268
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 11, 14, temp2, temp3) 27-53
			temp1++
			temp2 += 12
		loop
		temp2 = 78
		temp0++
		temp3 += 15
	loop

	//Uppercase Large Font | 54-79
	temp0 = 0
	temp2 = 78
	temp3 = 298
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			if temp1 == 3
				if temp0 == 1
					SpriteFrame(0, 0, 27, 22, temp2, temp3) // Q
				else
					SpriteFrame(0, 0, 27, 20, temp2, temp3) 
				end if	
			else	
				SpriteFrame(0, 0, 27, 20, temp2, temp3) 
			end if
			temp1++
			temp2 += 28
		loop
		temp2 = 78
		temp0++
		temp3 += 21
	loop

	//Lowercase Large Font | 80-105
	temp0 = 0
	temp2 = 78
	temp3 = 298
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			if temp1 == 3
				if temp0 == 1
					SpriteFrame(0, 0, 27, 22, temp2, temp3) // Q
				else
					SpriteFrame(0, 0, 27, 20, temp2, temp3) 
				end if	
			else	
				SpriteFrame(0, 0, 27, 20, temp2, temp3) 
			end if
			temp1++
			temp2 += 28
		loop
		temp2 = 78
		temp0++
		temp3 += 21
	loop

	//Uppercase Tiny Font | 106-131
	temp0 = 0
	temp2 = 1
	temp3 = 242
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 5, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 6
	loop

	//Lowercase Tiny Font | 132-157
	temp0 = 0
	temp2 = 1
	temp3 = 254
	while temp0 < 2
		temp1 = 0
		while temp1 < 13
			SpriteFrame(0, 0, 5, 7, temp2, temp3) 
			temp1++
			temp2 += 5
		loop
		temp2 = 1
		temp0++
		temp3 += 7
	loop

	SpriteFrame(0, 0, 15, 12, 286, 255) 158 // 158 . small font
	SpriteFrame(0, 0, 15, 12, 302, 255) 158 // 159 ! small font

	// extras get your extras!!
	SpriteFrame(0, -5, 61, 11, 162, 486) //160
	SpriteFrame(-62, -24, 123, 48, 322, 158) // 161
	SpriteFrame(-62, -24, 123, 48, 322, 207) // 162
	SpriteFrame(0, 58, 120, 70, 307, 342) // 163
	SpriteFrame(0, 58, 120, 70, 428, 342) // 164
	SpriteFrame(0, 58, 120, 70, 307, 413) // 165
	SpriteFrame(0, 58, 120, 70, 428, 413) // 166	
	SpriteFrame(0, 58, 120, 70, 442, 269) // 167

	// char select bos rush
	SpriteFrame(-8, -8, 16, 16, 17, 486) // 168
	SpriteFrame(-16, -3, 6, 7, 1, 503) // 169
	SpriteFrame(10, -3, 6, 7, 8, 503) // 170
	
	// tiny numbers 171-180
	temp1 = 0
	temp2 = 1
	while temp1 < 10
		SpriteFrame(0, 0, 5, 5, temp2, 269) 
		temp1++
		temp2 += 5
	loop

	// 181-204 achievements
	temp0 = 0
	temp2 = 1
	temp3 = 342
	while temp0 < 4
		temp1 = 0
		while temp1 < 6
			SpriteFrame(0, 0, 50, 35, temp2, temp3) 
			temp1++
			temp2 += 51
		loop
		temp2 = 1
		temp0++
		temp3 += 36
	loop
	SpriteFrame(0, 0, 1, 6, 52, 269) // 205 . 
	SpriteFrame(0, 0, 1, 6, 54, 269) // 206 , 
	SpriteFrame(0, 0, 1, 6, 56, 269) // 207 ' 
	SpriteFrame(0, 0, 1, 6, 58, 269) // 208 ! 
	SpriteFrame(0, 0, 15, 12, 234, 268) // 209 small :
	SpriteFrame(0, 0, 15, 12, 250, 268) // 210 small -

	temp1 = 0
	temp2 = 266
	while temp1 < 10
		SpriteFrame(0, 0, 15, 12, temp2, 268) // 211-220
		temp1++
		temp2 += 16
	loop
	SpriteFrame(0, 0, 15, 12, 234, 281) // 221
	SpriteFrame(0, 0, 15, 12, 250, 281) // 222
	SpriteFrame(0, 0, 15, 12, 266, 281) // 223
	SpriteFrame(0, -3, 6, 7, 282, 281) // 224
	SpriteFrame(0, 0, 3, 5, 60, 269) // 225
	SpriteFrame(-107, 0, 14, 20, 63, 298) // 226
	SpriteFrame(94, 0, 14, 20, 63, 319) // 227
	SpriteFrame(-87, 0, 14, 20, 63, 298) // 228
	SpriteFrame(74, 0, 14, 20, 63, 319) // 229
	SpriteFrame(-12, -12, 24, 24, 205, 450) // 230
	SpriteFrame(-12, -12, 24, 24, 230, 450) // 231
	SpriteFrame(-8, -7, 16, 14, 255, 450) // 232
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
